﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using shop.cart;

namespace comix
{
    public partial class bookcontrol : System.Web.UI.UserControl
    {
        public Book book;
        public string color;

        protected void Page_Load(object sender, EventArgs e)
        {
            maindiv.Style.Add("background-color", color);
            LCustomer cst = (LCustomer)Session["customer"];
            bok_titleLabel.Text = book.Title;
            bok_infoLabel.Text = book.Description;
            if (book.Owned)
            {
                bok_price.Text = "ΑΓΟΡΑΣΜΕΝΟ";
                bok_price.NavigateUrl = "";
            }
            else
            {
                bok_price.Text = book.Price.ToString() + "€";
                bok_price.Attributes.Add("name", "n" + book.Id.ToString());
                if (cst.Id == -1)
                    bok_price.Attributes.Add("onclick", "alert('Για να προχωρήσετε σε αγορές θα πρέπει να έχετε κάνει LogIn στο σύστημα');$('#accountmain').show();return false;");
                else
                    bok_price.Attributes.Add("onclick", "addToCartAjax(" + book.Id.ToString() + ");return false;");
            }
            infolink.NavigateUrl = "bookdetails.aspx?id=" + book.Id.ToString();
            ImageButton1.ImageUrl = book.SmallThumbnailPath();

            int intrate = Convert.ToInt32(Math.Floor(book.Rating));
            Star2.ImageUrl = "graphics/emptystar.png";
            Star3.ImageUrl = "graphics/emptystar.png";
            Star4.ImageUrl = "graphics/emptystar.png";
            Star5.ImageUrl = "graphics/emptystar.png";

            if (book.Rating > 1.33)
                Star2.ImageUrl = "graphics/halfstar.png";
            if (book.Rating > 1.66)
                Star2.ImageUrl = "graphics/filledstar.png";
            if (book.Rating > 2.33)
                Star3.ImageUrl = "graphics/halfstar.png";
            if (book.Rating > 2.66)
                Star3.ImageUrl = "graphics/filledstar.png";
            if (book.Rating > 3.33)
                Star4.ImageUrl = "graphics/halfstar.png";
            if (book.Rating > 3.66)
                Star4.ImageUrl = "graphics/filledstar.png";
            if (book.Rating > 4.33)
                Star5.ImageUrl = "graphics/halfstar.png";
            if (book.Rating > 4.66)
                Star5.ImageUrl = "graphics/filledstar.png";
        }

        /*
        protected void AddToCart(object sender, CommandEventArgs e)
        {
            Cart cart = (Cart)Session["cart"];
            CartItem ci = new CartItem();
            ci.Item = book;
            cart.Add(ci);
        }*/
    }
}